package org.jks.sms;

import org.smslib.IInboundMessageNotification;
import org.smslib.InboundMessage;
import org.smslib.OutboundMessage;
import org.smslib.Message.MessageEncodings;
import org.smslib.Message.MessageTypes;
import org.smslib.Service;

public class InboundNotification implements IInboundMessageNotification
{
	private static Service srv = null;
	
	public InboundNotification(Service srv)
	{
		InboundNotification.srv = srv;
	}
	
	public void process(String gatewayId, MessageTypes msgType, InboundMessage msg)
	{
		if(msgType != MessageTypes.INBOUND){
			return;
		}
		String text = SmsCmd.parseCmd(msg.getText());
		OutboundMessage outmsg = new OutboundMessage(msg.getOriginator(), text);
		outmsg.setEncoding(MessageEncodings.ENCUCS2);
		try {
			srv.sendMessage(outmsg);
		} catch (Exception e) {
			e.printStackTrace();
		} 
		
		try
		{
			srv.deleteMessage(msg);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}